<template>
	<view class="content font_family">
		<view class="item f_j" v-for="(item,index) in address_list" :key="index" @click="check_address(index,item)">
			<view class="left f_zj">
				{{item.name.slice(0,1)}}
			</view>
			<view class="msg">
				<view class="name">
					<text>{{item.name}}</text>
					<text class="phone">{{item.tel}}</text>
				</view>
				<view class="address">
					{{item.address+item.xx_address}}
				</view>
			</view>
			<image src="../../static/public/set.png" mode="" @click.stop="set(item)"></image>
		</view>
		<view class="btn_box ">
			<view class="btn f_zj" @click="go('/pages/my_msg/edit_address')">
				<image src="../../static/public/add_dz.png" mode=""></image>
				<view class="">
					添加收货地址
				</view>
			</view>
		</view>
		<u-empty text='还未配置收货地址哦~' icon="/static/public/kong.png" v-if="address_list.length==0">
		</u-empty>
	</view>
</template>

<script>
	import { mapMutations, mapState } from 'vuex'
	import { addressList } from '@/api/user.js'
	export default {
		computed: {
			...mapState(['address_list'])
		},
		data() {
			return {
				type: '',
			}
		},
		onLoad(e) {
			this.type = e.msg
		},
		onShow() {
			this.get_address()
		},
		methods: {
			...mapMutations(['set_address_list', 'set_address_check', 'set_j_msg']),
			get_address() {
				// 获取用户收货地址
				addressList().then(res => {
					if (res.code == 1) {
						this.set_address_list(res.data)
					}
				})
			},
			set(item) {
				let obj = JSON.stringify(item)
				uni.navigateTo({
					url: `/pages/my_msg/edit_address?obj=${obj}&id=${item.id}`
				})
			},
			check_address(index, item) {
				if (this.type == 'check') {
					this.set_address_check(index)
					this.back()
				} else if (this.type == 'jh') {
					let obj = {
						name: item.name,
						tel: item.tel,
						address: item.address,
						xx_address: item.xx_address
					}
					this.set_j_msg(obj)
					this.back()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #FFFFFF;

		.item {
			padding: 30rpx;

			.left {
				border-radius: 50%;
				width: 85rpx;
				height: 85rpx;
				background: rgba(238, 65, 51, 0.15);
				font-weight: 600;
				font-size: 28rpx;
				color: #EE4133;
			}

			.msg {
				margin: 0rpx 20rpx;
				flex: 1;

				.name {
					font-weight: 600;
					font-size: 28rpx;
					color: #232323;

					.phone {
						font-weight: 400;
						font-size: 28rpx;
						color: #232323;
					}
				}

				.address {
					margin-top: 10rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #666666;
				}
			}

			image {
				width: 26rpx;
				height: 26rpx;
			}
		}

		.btn_box {
			margin-top: 30rpx;
			padding: 30rpx;

			.btn {
				background: #EE4133;
				border-radius: 47rpx 47rpx 47rpx 47rpx;
				padding: 25rpx 0rpx;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;

				image {
					width: 28rpx;
					height: 28rpx;
					margin-right: 15rpx;
				}
			}
		}
	}
</style>